package com.check.controller;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.check.pojo.MarkTable;
import com.check.pojo.Pcwh;
import com.check.service.MarkDataService;
import com.check.service.MarkTableService;
import com.check.service.PcwhService;

@Controller
public class MarkResetController extends BaseController{

	@Autowired
	@Qualifier("pcwhService")
	private PcwhService pcwhService;
	
	@Autowired
	@Qualifier("markDataService")
	private MarkDataService markDataService;
	
	@Autowired
	@Qualifier("markTableService")
	private MarkTableService markTableService;
	
	@RequestMapping("markReset.do")
	public ModelAndView markReset(HttpServletRequest request,HttpServletResponse response){
		List<Pcwh> pcwhList = pcwhService.findAllPcwh();
		List<MarkTable> markTableList = markTableService.findAllActiveTable();
		return new ModelAndView("page/markReset/markReset")
					.addObject("path",request.getContextPath())
					.addObject("pcwhList",pcwhList)
					.addObject("markTableList",markTableList);
	}
	
	@RequestMapping("markResetSubmit.do")
	public void markResetSubmit(HttpServletRequest request,HttpServletResponse response){
		String checkYear = request.getParameter("checkYear");
		String checkId = request.getParameter("checkId");
		String tableType = request.getParameter("tableType");
		PrintWriter out=null;
		String flag = "0";
		saveSysLog(RE_MARKRESET, LOG_RESET, request);
		try{
			response.setContentType("text/html;charset=gbk");
			out=response.getWriter();
			boolean result = markDataService.updateMarkReset(checkYear,checkId,tableType);
			if(result){
				flag="1";
			}else{
				flag="0";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			out.print(flag);
			if(out != null){
				out.flush();
				out.close();
			}
		}
	
	}
}
